package com.itheima.d2_recursion;

import java.io.File;
import java.io.IOException;

public class RecursionDemo1 {
    public static void main(String[] args) throws IOException {
        searchFile(new File("D:"),"WeChat.exe");
    }

    public static void searchFile(File dir,String fileName) throws IOException {
        if(dir ==null||!dir.exists()||dir.isFile()){
            return;
        }

        File[] files = dir.listFiles();
        if(files!=null||files.length>0){
            for (File f : files) {
                if(f.isFile()){
                    if(f.getName().contains(fileName)){
                        System.out.println("找到了文件："+f.getAbsolutePath());
                        Runtime runtime = Runtime.getRuntime();
                        runtime.exec(f.getAbsolutePath());
                    }else {
                        searchFile(f,fileName);
                    }
                    }
                }
            }
        }
    }

